<template>
	<view class="container">
		<block v-for="item,index in jiaobenList">
		<view class="top">
			<text>脚本({{index+1}})</text>
			<image src="../../static/images/delete.png" :data-index="index" @click="delJiaoben" style="height: 40rpx;width: 40rpx;"></image>
		</view>
		<view class="jiaoben">
			<view class="jiaoben-title">
				脚本名称<text style="color: red;">*</text>
			</view>

			<input class="jiaoben-input" v-model="item.messageTitle" focus placeholder="请输入" />
		</view>
		<view class="jiaoben">
			<view class="jiaoben-title">
				脚本内容<text style="color: red;">*</text>
			</view>

			<input class="jiaoben-input" v-model="item.message" placeholder="请输入" />
		</view>
		</block>
		<view class="addBtn" @click="addJiaoben">
			+ 添加脚本
		</view>
		<view style="background-color: #fff;margin-top: 20rpx;border-top: 20rpx solid #f1f1f1;padding: 20rpx 0;">

			<view class="jingtou">
				<view class="shichang">镜头时长(s): </view>
				<view class="shichang-value">
					<input class="value-input" type="number" v-model="jingtouShichang1" />
					<text>--</text>
					<input class="value-input" type="number" v-model="jingtouShichang2" />
				</view>
			</view>
			<view class="jingtou">
				<view class="shichang">场景镜头数量(个): </view>
				<view class="shichang-value">
					<input class="value-input" type="number" v-model="jingtouShuliang1" />
					<text>--</text>
					<input class="value-input" type="number" v-model="jingtouShuliang2" />
				</view>
			</view>
		</view>
		<view class="footer" @click="submitJiaoben">
			提交
		</view>
	</view>


</template>

<script>
import Http from '../../utils/http'
const http = new Http()
	export default {
		data() {
			return {
				cateage:'',
               jiaobenList:[
				   {
					   messageTitle:"",
					   message:""
				   }
			   ],
			   jingtouShichang1:1,
			   jingtouShichang2:10,
			   jingtouShuliang1:1,
			   jingtouShuliang2:60

			}
		},
		onLoad(option) {
			console.log(option);
			this.cateage = option.id;
		},
		methods: {
			//添加脚本
			addJiaoben() {
              let item =  {
					   messageTitle:"",
					   message:""
				   }
				   this.jiaobenList.push(item)
			},
			delJiaoben(e){
				let index = e.currentTarget.dataset.index
				this.jiaobenList.splice(index,1)
			},
			//提交脚本
			submitJiaoben(){
				if(this.cateage == '6' && this.jiaobenList.length != 3){
					uni.showToast({
						title:"至少要上传三个脚本",
						icon:'none',
					})
					return false;
				}
				http.post("v1/jiaoben/add",{message:JSON.stringify(this.jiaobenList),type:2,cateage:this.cateage}).then(res=>{
					if(res.data.code!=200){
						 uni.showToast({
							title:"保存失败"
						})
					}else{
						 uni.showToast({
							title:"保存成功"
						})
						var pages = getCurrentPages()
						let prePage = pages[pages.length-2]
						uni.navigateBack({delta:1})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #f1f1f1;
	}

	.container {
		// width: 100vw;
		height: 100%;
		padding-bottom: 100rpx;

		.top {
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			background: #eee;
			color: #666;
			font-size: 30rpx;
		}

		.jiaoben {
			padding: 20rpx;
			display: flex;
			font-size: 36rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid #f1f1f1;
			background: #ffffff;

			.jiaoben-title {
				width: 200rpx;
			}

			.jiaoben-input {
				color: #666;
				font-size: 34rpx;
				flex: 1;
			}
		}

		.addBtn {
			width: 100%;
			align-items: center;
			color: blue;
			display: flex;
			padding: 20rpx 0;
			justify-content: center;
			font-size: 32rpx;
			background-color: #ffffff;
		}

		.jingtou {
			padding: 0rpx 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;

			.shichang {
				width: 300rpx;
				font-size: 32rpx;
			}
		}

		.shichang-value {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.value-input {
			width: 110rpx;
			height: 70rpx;
			background: #eee;
			color: #333;
			font-size: 30rpx;
			border-radius: 12rpx;
			text-align: center;
		}
	}

	.footer {
		width: 96%;
		height: 80rpx;
		background: rgb(14, 16, 101);
		color: #ffffff;
		font-size: 32rpx;
		border-radius: 12rpx;
		position: fixed;
		left: 2%;
		bottom: 20rpx;
		text-align: center;
		line-height: 80rpx;
	}
</style>